/*
 * Copyright (c) 2009, Servoy-stuff
 * 
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 * 
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 * http://www.fsf.org/licensing/licenses/lgpl.txt
 */
package net.stuff.servoy.beans.svg;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Point;
import java.io.Serializable;

import com.servoy.j2db.IServoyBeanFactory;
import com.servoy.j2db.plugins.IClientPluginAccess;
import com.servoy.j2db.ui.IComponent;

/**
 * @author Servoy Stuff
 * http://www.servoy-stuff.net/
 */
public class SVGBean implements IServoyBeanFactory, Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private SVGSwingBean component = new SVGSwingBean();
	
	private Point location;
	private String name;
	private Dimension size;
	private boolean showInStatus;
	private boolean allowUserInteractions;
	private Color background = new Color(255,255,255,0);
	private boolean opaque;
	
    private String defaultURI;
    private String dataProvider;


	/* (non-Javadoc)
	 * @see com.servoy.j2db.IServoyBeanFactory#getBeanInstance(int, com.servoy.j2db.plugins.IClientPluginAccess, java.lang.Object[])
	 */
	public IComponent getBeanInstance(int mode,
			IClientPluginAccess app,
			Object[] paramArrayOfObject) {
		if (mode != IClientPluginAccess.WEB_CLIENT) {
			initComponent(app);
			return component;
		}
		return null;
	}

	/**
	 * @param app
	 */
	private void initComponent(IClientPluginAccess app) {
		component.initialize(app);
		if (location != null) setLocation(location);
		if (name != null) setName(name);
		if (size != null) setSize(size);
		setShowInStatus(showInStatus);
		setAllowUserInteractions(allowUserInteractions);
		setBackground(background);
		setOpaque(opaque);
		if (defaultURI != null) setDefaultURI(defaultURI);
		if (dataProvider != null) setDataProvider(dataProvider);
	}

	/* (non-Javadoc)
	 * @see com.servoy.j2db.persistence.Zdb#getName()
	 */
	public String getName() {
		return this.name;
	}

	/**
	 * @return the location
	 */
	public Point getLocation() {
		return this.location;
	}

	/**
	 * @param location the location to set
	 */
	public void setLocation(Point location) {
		this.location = location;
		if (component != null) {
			component.setLocation(location);
		}
	}

	/**
	 * @return the size
	 */
	public Dimension getSize() {
		return this.size;
	}

	/**
	 * @param size the size to set
	 */
	public void setSize(Dimension size) {
		this.size = size;
		if (component != null) {
			component.setSize(size);
		}
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
		if (component != null) {
			component.setName(name);
		}
	}

	public boolean isShowInStatus() {
		return showInStatus;
	}

	public void setShowInStatus(boolean showInStatus) {
		this.showInStatus = showInStatus;
		if (component != null) {
			component.setShowInStatus(showInStatus);
		}
	}

	public boolean isAllowUserInteractions() {
		return allowUserInteractions;
	}

	public void setAllowUserInteractions(boolean allowUserInteractions) {
		this.allowUserInteractions = allowUserInteractions;
		if (component != null) {
			component.setAllowUserInteractions(allowUserInteractions);
		}
	}

	/**
	 * @return the defaultURI
	 */
	public String getDefaultURI() {
		return this.defaultURI;
	}

	/**
	 * @param defaultURI the defaultURI to set
	 */
	public void setDefaultURI(String defaultURI) {
		this.defaultURI = defaultURI;
		if (component != null) {
			component.setDefaultURI(defaultURI);
		}
	}

	/**
	 * @return the dataProvider
	 */
	public String getDataProvider() {
		return this.dataProvider;
	}

	/**
	 * @param dataProvider the dataProvider to set
	 */
	public void setDataProvider(String dataProvider) {
		this.dataProvider = dataProvider;
		if (component != null) {
			component.setDataProvider(dataProvider);
		}
	}

	/**
	 * @return the background
	 */
	public Color getBackground() {
		return background;
	}

	/**
	 * @param background the background to set
	 */
	public void setBackground(Color background) {
		this.background = background;
		if (component != null && background != null) {
			component.setBackground(background);
		}
	}

	/**
	 * @return the opaque
	 */
	public boolean isOpaque() {
		return opaque;
	}

	/**
	 * @param opaque the opaque to set
	 */
	public void setOpaque(boolean b) {
		this.opaque = b;
		if (component != null) {
			component.setOpaque(b);
		}
	}

}
